<?php echo $this->Html->addCrumb('Quản lý đơn đặt hàng')?>
<div class="accountPage">
>> <?php //echo $this->Html->link('Thêm mới đơn đặt hàng',array('action'=>'add','controller'=>'orders'))?>
<legend>Tìm kiếm</legend>
<?php echo $this->Form->create('Order',array('type'=>'get','id'=>'searchForm'))?>
<table width='100%'>
<tr>
	<td><?php echo $this->Form->input('name',array('required'=>false,'label'=>'Tên khách hàng','type'=>'text','value'=>$name))?></td>
	<td><?php echo $this->Form->input('payment_type_id',array('empty'=>true,'required'=>false,'label'=>'Cách thanh toán','options'=>$opt_payment,'selected'=>$payment_type_id))?></td>
	<td><?php echo $this->Form->input('shipping_type_id',array('empty'=>true,'required'=>false,'label'=>'Cách chuyển hàng','options'=>$opt_shipping,'selected'=>$shipping_type_id))?></td>
</tr>
<tr>
	<td>
	Giá từ<br/><?php echo $this->Form->input('price_from',array('required'=>false,'div'=>false,'label'=>false,'type'=>'number','size'=>5,'value'=>$price_from))?>
	đến <?php echo $this->Form->input('price_to',array('required'=>false,'div'=>false,'label'=>false,'type'=>'number','size'=>5,'value'=>$price_to))?> VND
	</td>	
	<td><?php echo $this->Form->input('order_status_id',array('empty'=>true,'required'=>false,'label'=>'Tình trạng đơn hàng','options'=>$opt_status,'selected'=>$order_status_id))?></td>	
	<td><?php echo $this->Form->input('delivery_date',array('empty'=>true,'required'=>false,'label'=>'Ngày sinh','type'=>'date','dateFormat'=>'DMY','monthNames'=>false,'separator'=>' ','value'=>$delivery_date))?></td>
</tr>
<tr>
	<td colspan='3'><?php echo $this->Form->submit('Bắt đầu tìm')?><?php echo $this->Form->reset('Xóa trắng')?></td>
</tr>
</table>
<?php echo $this->Form->end()?>

<div id='searchResult'>
<h3>Danh sách đơn hàng</h3>
<table id='tableCart'>
<col width='10%'/>
<col width='25%'/>
<col width='10%'/>
<col width='15%'/>
<col width='10%'/>
<col width='10%'/>
<col width='10%'/>
<col width='10%'/>
<tr>
	<th>STT</th>
	<th>Tên KH</th>	
	<th>Thanh toán</th>
	<th>Chuyển hàng</th>	
	<th>Tổng cộng</th>	
	<th>Tình trạng</th>
	<th>Ngày đặt hàng</th>
	<th></th>
</tr>
<?php if(!empty($rs)):?>
<?php
$i = 0;
foreach($rs as $item):
$i++;
?>
<tr>
	<td><?php echo $i?></td>
	<td><?php echo $this->Html->link(h($item['Customer']['name']),array('action'=>'detail','controller'=>'orders',$item['Order']['id']))?></td>
	<td><?php echo h($item['PaymentType']['name'])?></td>
	<td><?php echo h($item['ShippingType']['name'])?></td>
	<td><?php echo h($item['Order']['total'])?></td>
	<td><?php echo h($item['OrderStatus']['name'])?></td>
	<td><?php echo h($item['Order']['created'])?></td>
	<td>
	<?php echo $this->Html->link('Xóa',array('action'=>'delete','controller'=>'orders',h($item['Order']['id'])),null,'Bạn thật sự muốn xóa?')?>
	<?php //echo $this->Html->link('Sửa',array('action'=>'edit','controller'=>'orders',h($item['Order']['id'])))?>	
	</td>
</tr>
<?php endforeach;?>
<?php else:?>
<tr><td colspan='6'>Không tìm thấy dữ liệu</td></tr>
<?php endif;?>
</table>
<?php echo $this->element('paging')?>
</div>

</div>
<script language='javascript' type='text/javascript'>
$().ready(function(){
	$('#searchForm').submit(function(e){
		e.preventDefault();
		var name = $('input[name="name"]').val();
		var payment_type_id = $('select[name="payment_type_id"]').val();
		var shipping_type_id = $('select[name="shipping_type_id"]').val();		
		var price_from = $('input[name="price_from"]').val();
		var price_to = $('input[name="price_to"]').val();
		var order_status_id = $('select[name="order_status_id"]').val();
		var delivery_date_day = $('select[name="delivery_date[day]"]').val();
		var delivery_date_month = $('select[name="delivery_date[month]"]').val();
		var delivery_date_year = $('select[name="delivery_date[year]"]').val();
		$.ajax({
			url : '<?php echo $this->Html->url(array('action'=>'index','controller'=>'orders'))?>',
			data : {
				name : name,
				payment_type_id : payment_type_id,
				shipping_type_id : shipping_type_id,
				price_from : price_from,				
				price_to : price_to,				
				order_status_id : order_status_id,				
				delivery_date_day : delivery_date_day,				
				delivery_date_month : delivery_date_month,				
				delivery_date_year : delivery_date_year,				
			},
			//dataType : 'json',
			success : function(html, textStatus) {
				$('#searchResult').html(html);
				//alert('Success ' + textStatus + html);
			},
			error : function(xhr, textStatus, errorThrown) {
				//alert('An error occurred! ' + errorThrown);
			}
		});
	});
});
</script>